<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    let url = 'https://www.imooc.com/api/http/json/search/suggest?word=js'
    const fd = new FormData()
    fd.append('username', 'fdaf')

    fetch(url, {
      method: 'post',
      // body:null,
      // 不支持json
      // body:{
      //   name:'232'
      // }


      // headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
      // body: 'username=qw&age=19'

      // headers: { 'Content-Type': 'application/json' },
      // body: JSON.stringify({
      //   name: '323'
      // }),

      // Content-Type: multipart/form-data
      body: fd,
      credentials: 'include',// 跨域携带cookie
      mode: 'cors' // 跨域

    }).then(res => {
      console.log(res)
      if (res.ok) {
        return res.json()
        // return res.text()
      } else {
        throw new Error(`HTTP异常,${res.status}`)
      }
    }).then((data) => {
      console.log(data)
    }).catch(err => {
      console.log(err)
    })

  </script>
</body>

</html>